package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServiceimpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> listRoles(String name, String label,  Integer page,  Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Role> list=roleMapper.listRoles(name,label);
        Page<Role> r= (Page<Role>) list;
        return new PageResult<>(r.getTotal(),r.getResult());
    }

    @Override
    public void deleleByid(Integer id) {
        roleMapper.deletetoid(id);
    }

    @Override
    public void insert(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insertList(role);
    }

    @Override
    public Role getById(Integer id) {
        Role role = roleMapper.selectByid(id);
        return role;
    }

    @Override
    public void updaterole(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.updaterole(role);
    }

    @Override
    public List<Role> selectAll() {
        List<Role> roles = roleMapper.selectAll();
        return  roles;
    }


}
